//
//  DSTabBarCtr.swift
//  weibo
//
//  Created by apple on 16/7/18.
//  Copyright © 2016年 小环. All rights reserved.
//

import UIKit

class DSTabBarCtr: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //添加四个子控制器
        addChildCtrs()
        
        let newTabBar=DSMainTabBar()
        setValue(newTabBar, forKey: "tabBar")
        newTabBar.tintColor=UIColor.orangeColor()
        //准备闭包
        newTabBar.composeClosure={()->() in
            print("撰写按钮被点击了")
        }
    }
    
    //添加四个子控制器
    private func addChildCtrs(){
        
        //获取控制器
        let Home=DSHomeTableCtr()
        addChildViewController(Home, title: "首页", imageName: "tabbar_home")
        
        let Message=DSMessageTableCtr()
        addChildViewController(Message, title: "信息", imageName: "tabbar_message_center")
        
        let Find=DSFindTableCtr()
        addChildViewController(Find, title: "发现", imageName: "tabbar_discover")
        
        let Profile=DSProfileTableCtr()
        addChildViewController(Profile, title: "我", imageName: "tabbar_profile")
    }
    
    private func addChildViewController(childController: UIViewController,title:String,imageName:String) {
        
        childController.title=title
        childController.tabBarItem.image=UIImage(named:imageName)
        
        childController.tabBarItem.selectedImage=UIImage(named: "\(imageName)_selected")
        
        self.addChildViewController(UINavigationController(rootViewController:childController))
    }
}
